package com.ctgu.springshiro.controller;

import com.ctgu.springshiro.enums.StatusCodeEnum;
import com.ctgu.springshiro.utils.BaseResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BaseController {

    private static final Logger log= LoggerFactory.getLogger(BaseController.class);

    @GetMapping("/welcome")
    public String welcome(String name, ModelMap map){
        if (StringUtils.isBlank(name)){
            name="这是welcome!";
        }
        map.addAttribute("name", name);
        return "welcome";
    }

    @GetMapping("/data")
    @ResponseBody
    public String data(String name){
        if (StringUtils.isBlank(name)){
            name="这是welcome!";
        }
        return name;
    }

    @GetMapping("/response")
    @ResponseBody
    public BaseResponse response(String name){
        BaseResponse response=new BaseResponse(StatusCodeEnum.Success);
        if (StringUtils.isBlank(name)){
            name="这是welcome!";
        }
        response.setData(name);
        return response;
    }

    @GetMapping("/error")
    public String error(){
        return "error";
    }
}
